﻿/****************
 * 选择老人弹窗 *
 ****************/

// initValue：绑定值
// option:{width:容器宽度,servicePersonId:赋值姓名文本框Id,ContactNumberId:赋值联系电话文本框Id,elemId:输入框inputId}
function servicePersonSelect(initValue, option) {
    var width = '';//默认宽度
    var servicePersonId = 'servicePersonId';//默认赋值inputId
    var elemId = 'servicePersonName';//默认输入框Id
    var ContactNumberId = 'ContactNumber';//联系电话输入框Id
    if (option == null || option == undefined) {
        option = { width: width, servicePersonId: servicePersonId, elemId: elemId };
    }
    if (option.width == '' || option.width == null || option.width == undefined) {
        option.width = width;
    }
    if (option.servicePersonId == '' || option.servicePersonId == null || option.servicePersonId == undefined) {
        option.servicePersonId = inputShowId;
    }
    if (option.ContactNumberId == '' || option.ContactNumberId == null || option.ContactNumberId == undefined) {
        option.ContactNumberId = ContactNumberId;
    }
    tableSelect.render({
        elem: '#' + option.elemId,	//定义输入框input对象
        width: option.width,
        checkedKey: 'Id', //表格的唯一建值，非常重要，影响到选中状态 必填
        searchKey: 'Name',	//搜索输入框的name值 默认keyword
        searchPlaceholder: '关键词搜索',	//搜索输入框的提示文字 默认关键词搜索
        table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
            id: 'ptable',
            url: setter.baseServer + '/ClientManage/ServicePerson/GetPageListJson',
            limit: 6,
            limits: [6],
            where: option.where,
            size: 'sm',
            cols: [[
                { type: 'radio' },
                { field: 'Name', title: '姓名', width: 120, sort: true },
                {
                    field: 'Sex', title: '性别', width: 80, templet: function (d) {
                        if (d.Sex == 1) return "男";
                        if (d.Sex == 2) return "女";
                    }
                },
                { field: 'IdCardNumber', title: '身份证号码', width: 180, sort: true },
                { field: 'PhoneNumber', title: '联系电话', width: 120, sort: true }

            ]],
            done: function () {
                // $('.tableSelect').css("width",'300px');
                if (initValue != 0) {
                    $("#" + option.elemId).val(table.cache["ptable"].filter(function (item, index) {
                        return item.ServicePersonId == initValue;
                    })[0].Name);
                }
            }
        },
        done: function (elem, data) {
            elem.val(data.data[0].Name);
            $("#" + option.servicePersonId).val(data.data[0].Id);
            $("#" + option.ContactNumberId).val(data.data[0].PhoneNumber);
            //选择完后的回调，包含2个返回值 elem:返回之前input对象；data:表格返回的选中的数据 []
            //拿到data[]后 就按照业务需求做想做的事情啦~比如加个隐藏域放ID...
        }
    })
}